<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2017/11/20
 * Time: 下午5:26
 */

namespace App\Console\Commands;

use App\Modules\Agent\Services\AgentServices;
use App\Modules\BackCost\Models\HbGzh;
use App\Modules\BackCost\Models\HbMonthStats;
use App\Modules\BackCost\Services\HbGzhsServices;
use App\Modules\BackCost\Services\HbMonthStatsServices;
use App\Modules\Channel\Services\ChannelDailyStatService;
use App\Modules\SendOrder\Models\SendOrder;
use App\Modules\SendOrder\Services\SendOrderService;
use App\Modules\Trade\Services\OrderService;
use App\Modules\User\Models\UserSubscribeBehaviorStats;
use DB;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Log;

class tempTask extends Command
{
    /**
     * 执行命令 获取站点的派单数据及服务号信息
     *
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'temp_task';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '获取站点的派单数据及服务号信息';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        echo 'start:'.date('Y-m-d H:i:s');
        $cookie = 'JSESSIONID=0EAB66E42C5C4E57E6C2D421BA3F1E83; SPRING_SECURITY_REMEMBER_ME_COOKIE=MTU4NzQyODY3MTI6MTU2NzkxMjI0NTk1Njo1YzU1NWU3NTIxODg5ZjBkODM5MTc5NWE3YzhjNWRkMg';
        $header[] = "Cookie: ".$cookie;

        $home_url = 'http://218.76.24.159:23008/specSpecimenInfo/pagingShowList?flag=1&sortColumns=create_time&detailFlag=1&enFlag=0';
        $ch = curl_init($home_url);

        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        //设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //设置post方式提交
        curl_setopt($ch, CURLOPT_POST, 1);
        //设置post数据
        $post_data = array(
            "sEcho" => 1,
            "iColumns" => 10,
            'iDisplayStart'=>1,
            'iDisplayLength'=>6000,
            'provinceId'=>430000,
            'cityId'=>430900,
            'countryId'=>430922
         );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $response = curl_exec($ch);
        curl_close($ch);
        //var_dump($response);
        $ret = json_decode($response,true);
        //var_dump($ret['aaData']);
        foreach ($ret['aaData'] as $each){
            if($each['groupOnline']=='在线') {
                $this->withdraw($header,$each['specimenId']);
                sleep(2);
            }
        }
        echo 'end:'.date('Y-m-d H:i:s');
    }

    public function withdraw($header,$ids) {

        $home_url='http://218.76.24.159:23008/specSpecimenInfo/reBatchSelectGroup?groupType=1';
        $ch = curl_init($home_url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        //设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //设置post方式提交
        curl_setopt($ch, CURLOPT_POST, 1);
        $post_data = array(
            'ids'=>$ids
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $response = curl_exec($ch);
        curl_close($ch);
        echo 'id'.$ids.':'.$response."\n";
    }
}